# RUN: llc %s -o - -experimental-debug-variable-locations \
# RUN:    -run-pass=greedy,virtregrewriter | FileCheck %s
#
# This test is for stack spill folding -- the SETCC near the start of the MIR
# below show be morphed into an SETCCm by the register allocator, making it
# store to %stack.0. We should track this fact in the substitution table, by
# adding a substitution to the memory-operand operand number.
#
# This is a single operand spill -- there's a separate test for tied def ones.
#
# Ideally this test would be shorter; however, it needs to be sufficiently
# complex to force the register allocator to spill something, so there's a
# limit.
#
# CHECK:      debugValueSubstitutions:
# CHECK-NEXT:  - { srcinst: 1, srcop: 0, dstinst: 2, dstop: 1000000, subreg: 0 }
# CHECK-LABEL: bb.0:
# CHECK: SETCCm %stack.0, {{.*}} debug-instr-number 2
--- |
  target triple = "x86_64--"
  
  define void @beans() !dbg !7  {
    ret void
  }
   
  !llvm.dbg.cu = !{!0}
  !llvm.module.flags = !{!3, !4, !5}
  !llvm.ident = !{!6}
  
  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
  !1 = !DIFile(filename: "test.c", directory: ".")
  !2 = !{}
  !3 = !{i32 7, !"Dwarf Version", i32 4}
  !4 = !{i32 2, !"Debug Info Version", i32 3}
  !5 = !{i32 1, !"wchar_size", i32 4}
  !6 = !{!"clang"}
  !7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !8, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
  !8 = !DISubroutineType(types: !9)
  !9 = !{!10, !11, !11}
  !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  !11 = !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed)
  !12 = !DILocalVariable(name: "bar", arg: 1, scope: !7, file: !1, line: 3, type: !11)
  !13 = !DILocation(line: 0, scope: !7)
  !14 = !DILocalVariable(name: "baz", arg: 2, scope: !7, file: !1, line: 3, type: !11)
  !15 = distinct !DILexicalBlock(scope: !7, file: !1, line: 8, column: 7)


...
---
name: beans
tracksRegLiveness: True
debugInstrRef: true
body: |
  bb.0:
    liveins: $edi
    %7:gr32 = COPY $edi
    CMP32ri8 %7, 4, implicit-def $eflags
    %0:gr8 = SETCCr 4, implicit $eflags, debug-instr-number 1

    ; clobber all registers to force a spill/reload
    INLINEASM &nop, 1 /* sideeffect attdialect */, 12 /* clobber */, implicit-def dead early-clobber $rax, 12 /* clobber */, implicit-def dead early-clobber $rbx, 12 /* clobber */, implicit-def dead early-clobber $rcx, 12 /* clobber */, implicit-def dead early-clobber $rdx, 12 /* clobber */, implicit-def dead early-clobber $rsi, 12 /* clobber */, implicit-def dead early-clobber $rdi, 12 /* clobber */, implicit-def dead early-clobber $rbp, 12 /* clobber */, implicit-def dead early-clobber $r8, 12 /* clobber */, implicit-def dead early-clobber $r9, 12 /* clobber */, implicit-def dead early-clobber $r10, 12 /* clobber */, implicit-def dead early-clobber $r11, 12 /* clobber */, implicit-def dead early-clobber $r12, 12 /* clobber */, implicit-def dead early-clobber $r13, 12 /* clobber */, implicit-def dead early-clobber $r14, 12 /* clobber */, implicit-def dead early-clobber $r15

    $al = COPY %0
    RET 0, $al
...
